// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import moment from 'moment'


Vue.filter('dateFormat', function (datestr, mm) {
  return moment(datestr).format('YYYY-MM-DD HH:mm:ss')
})


Vue.config.productionTip = false

import './lib/dist/css/mui.min.css'
import './lib/dist/css/icons-extra.css'
import './lib/dist/fonts/mui-icons-extra.ttf'
import 'mint-ui/lib/style.css'

import vueResource from 'vue-resource'
Vue.use(vueResource)

import mintui from 'mint-ui'
Vue.use(mintui)

//axios使用
import axios from 'axios'
Vue.prototype.$ax = axios
axios.defaults.baseURL = 'http://www.liulongbin.top:3005'


Vue.http.options.root = 'http://www.liulongbin.top:3005'



import Vuex from "vuex"
Vue.use(Vuex)
var car=JSON.parse(localStorage.getItem('car')||'[]')
const store = new Vuex.Store({
  state: {
    car: car
  },
  mutations: {

    addToCar(state, goodsInfo) {
      var flag = false
      state.car.some(item => {
        if (item.id == goodsInfo.id) {
          item.count += parseInt(goodsInfo.count)
          flag = true
          return true
        }
      })
      if (!flag) {
        state.car.push(goodsInfo)
      }
      localStorage.getItem('car',JSON.stringify(state.car))
    }
  },
  getters: {
    getAllCount(state) {
      var c = 0
      state.car.forEach(item => {
        c += item.count
      })
      return c
    }
  },
  actions: {},
  modules: {}
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>',
  store
})
